import Qs from 'qs'
/*import {HOST} from 'common/js/config'
 import Request from 'common/js/request'

 /!*var api = HOST + '?g=api/mission&m=index&'*!/
 var api = HOST + '?g=api/public&m=v2&client=5&accesskey=519f9cab85c8059d17544947k361a827&';
 var api2 = HOST + '?g=api/pv3&m=index&client=5&accesskey=519f9cab85c8059d17544947k361a827&';*/
import {HOST, HOST2, ROUTERHOST} from 'common/js/config'
import Request from 'common/js/request'
import {getQueryString} from 'common/js/utl'


//var uid = getQueryString('uid') || localStorage.getItem('uid')
//var token = getQueryString('token') || localStorage.getItem('token')
// var api = HOST + `?g=api/shop&m=index&&accesskey=519f9cab85c8059d17544947k361a827&debug=1&`
var api = HOST + `?g=api/shop&m=index&accesskey=519f9cab85c8059d17544947k361a827&`;
var api2 = HOST2 + 'v1/app/';
var api3 = HOST2 + 'v1/';
var api4 = ROUTERHOST + `/api/v1/data/`;   /* http://router-h5.rrysapp.com/  */
//var api2 = HOST + `?g=api/public&m=v2&client=5&accesskey=519f9cab85c8059d17544947k361a827&uid=${uid}&token=${token}&`
//获取极验token
export function getGTCode () {
  // const area = '86'
  const url = api + `a=register_ini`;
  //const url = api + `a=login`
  return Request.get(url)
}

//极验校验并获取短信码
export function getCheckCode (params) {
  // const area = '86'
  // const url = api + `a=register_sms_code&area=${area}&mobile=${mobile}&geetest_challenge=${geetest_challenge}&geetest_validate=${geetest_validate}&geetest_seccode=${geetest_seccode}`
  const url = api + `a=register_sms_code`
  //const url = api + `a=login`
  return Request.post(url, params,{
    transformRequest: [function (data) {
      // Do whatever you want to transform the data
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}

export function getMbAreaCode () {
  let url;
  if (process.env.NODE_ENV == 'production') {
    url = `${application.base}static/data/area_code.json?v=2`;
  } else {
    url = `${application.base}static/data/area_code.json?v=2`;
  }

  // let url = `${application.base}static/data/areaCode.json?v=2`
  //const url = api + `a=login`
  return Request.get(url, {
    // headers: {
    //   'Accept': 'application/json',
    // },
    transformResponse: [function (data) {
      // 对 data 进行任意转换处理
      //debugger
      return {
        status: 1,
        data: JSON.parse(data)
      };
    }]
  })
}

// 获取用户所在国家代码
export function getCountryCode () {
  let url;
  if (process.env.NODE_ENV == 'production') {
    url = `${application.base}pc_html/static/data/user_country.json?v=2`;
  } else {
    url = `${application.base}static/data/user_country.json?v=2`;
  }

  //const url = api + `a=login`
  return Request.get(url, {
    // headers: {
    //   'Accept': 'application/json',
    // },
    transformResponse: [function (data) {
      // 对 data 进行任意转换处理
      //debugger
      return {
        status: 1,
        data: JSON.parse(data)
      };
    }]
  })
}

// 修改用户头像后提交上传
export function uploadFile (uid, token, data) {
  const url = api + `a=upload_avatar&uid=${uid}&token=${token}`;
  return Request.post(url, data, {
    headers: {'Content-Type': 'multipart/form-data'}
  })
}













// 收货地址查询接口
export function userAddress (uid) {
  const url = api + `a=user_address&uid=${uid}`;
  return Request.get(url)
}

// 新增收货地址接口
export function addUserAddress (uid, name, area, phone, address, postCode) {
  const url = api + `a=add_user_address&uid=${uid}&name=${name}&area=${area}&phone=${phone}&address=${address}&post_code=${postCode}`;
  return Request.get(url)
}

// 修改收货地址接口
export function editUserAddress (uid, name, area, phone, address, postCode, id) {
  const url = api + `a=edit_user_address&uid=${uid}&name=${name}&area=${area}&phone=${phone}&address=${address}&post_code=${postCode}&id=${id}`;
  return Request.get(url)
}


// 获取商品价格接口
export function goodsPrice (uid, token, gid, num) {
  /*const url = api + `a=trans_price&price=${price}`;*/
  const url = api + `a=goods_price&uid=${uid}&token=${token}&gid=${gid}&num=${num}`;
  return Request.get(url)
}

// 用户下单接口
export function placeOrder (uid, token, data) {
  const url = api + `a=place_order&uid=${uid}&token=${token}`;
  return Request.post(url, data,{
    transformRequest: [function (data) {
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}

// 获取订单详情接口
export function orderDetail (uid, token, oid) {
  const url = api + `a=order_detail&uid=${uid}&token=${token}&oid=${oid}`;
  return Request.get(url)
}

// 订单支付接口
export function finishOrder (data) {
  const url = api + `a=order_pay`;
  return Request.post(url, data,{
    transformRequest: [function (data) {
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    }
  })
}

// 收货地址查询接口
export function clickNumber (gid) {
  const url = api + `a=buy_btn_click&gid=${gid}`;
  return Request.get(url)
}

// 获取用户信息接口
export function userInfo (uid, token) {
  const url = api + `a=userinfo&uid=${uid}&token=${token}`;
  return Request.get(url)
}

// 删除用户地址接口
export function deleteUserAddress (uid, id) {
  const url = api + `a=del_user_address&uid=${uid}&id=${id}`;
  return Request.get(url)
}

// 设置默认收货地址接口
export function setDefaultAddress (uid, id) {
  const url = api + `a=set_default_address&uid=${uid}&id=${id}`;
  return Request.get(url)
}

// 取消订单接口
export function cancelOrder (uid, token, oid) {
  const url = api + `a=cancel_order&uid=${uid}&token=${token}&oid=${oid}`;
  return Request.get(url)
}

// 获取订单列表接口
export function orderList (uid, page) {
  const url = api + `a=user_order&uid=${uid}&page=${page}&pageSize=10`;
  return Request.get(url)
}

// 校验用户支付密码
export function checkPayPassword (data) {
  const url = api2 + `amount/checkPayPassword`;
  /*return Request.post(url, data,{
    transformRequest: [function (data) {
      let ret = ''
      for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
      }
      return ret
    }],
    headers: {
      "Content-Type":'application/json; charset=UTF-8'
    }
  })*/
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 极验初始化
export function geetestInit () {
  const url = api3 + `validate/geetestInit`;
  return Request.get(url)
}

// 支付密码验证成功后获取短信验证码
export function getCode (data) {
  const url = api + `a=send_code_shop_order`;
  return Request({
    url,
    method: 'post',
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: Qs.stringify(data)
  })
}

// 商城提交订单之前验证短信验证码
/*export function checkSMSCode (code) {
  const url = api + `a=check_code_shop_order&code=${code}`;
  return Request.get(url)
}*/
export function checkSMSCode () {
  const url = api + `a=check_code_shop_order`;
  return Request.get(url)
}

// 正式提交订单
export function submitOrder (data) {
  const url = api + `a=place_order`;
  return Request({
    url,
    method: 'post',
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: Qs.stringify(data)
  })
}

// 收益明细/*uid, token,   uid=${uid}&token=${token}& */
export function getIncomeDetail (page, per) {
  const url = api2 + `super/user/incomeDetailList?page=${page}&per=${per}`;
  return Request.get(url)
}

// 极验初始化/* uid, token, uid=${uid}&token=${token}& */
export function becomeSuperNodeMiner (code, nodeNum) {
  const url = api2 + `super/user/superInviteCode?code=${code}&nodeNum=1`;
  return Request.get(url)
}

// 判断用户身份 /* uid, token ?uid=${uid}&token=${token} */
export function judgeUserRole () {
  const url = api2 + `super/user/superNodeUid`;
  return Request.get(url)
}

// 节点质押用户信息
export function depositUserInfo () {
  const url = api2 + `pledge/userInfo`;
  return Request.get(url)
}

// 收益模式
export function incomeType (cvnt, status, source) {
  const url = api2 + `pledge/incomeType?cvnt=${cvnt}&status=${status}&source=${source}`;
  return Request.get(url)
}

// cvnt路由器或者linux端质押
export function cvntPledge (cvnt, source) {
  const url = api2 + `pledge/pledging?cvnt=${cvnt}&source=${source}`;
  return Request.get(url)
}

// cvnt路由器或者linux端质押提取
export function cvntWithdraw (cvnt, source) {
  const url = api2 + `pledge/draw?cvnt=${cvnt}&source=${source}`;
  return Request.get(url)
}

// 看板页持币排行榜
export function cvntRankList () {
  const url = api2 + `view/rank`;
  return Request.get(url);
}

// 获取挖矿信息接口
export function miningInfo (uid, token, source) {
  /*const url = api4 + `user/miningInfo?uid=${uid}&token=${token}&source=${source}&t=` + Date.now();*/
  const url = api2 + `user/miningInfo?uid=${uid}&token=${token}&source=${source}&t=` + Date.now();
  return Request.get(url)
}

// 获取挖矿设备接口
export function miningRouterList (uid, token, source, per, page) {
  /*const url = api4 + `user/miningRouterList?uid=${uid}&token=${token}&source=${source}&per=${per}&page=${page}&t=` + Date.now();*/
  const url = api2 + `user/miningRouterList?uid=${uid}&token=${token}&source=${source}&per=${per}&page=${page}&t=` + Date.now();
  return Request.get(url)
}

// 獲取經銷商信息
export function agentInfo () {
  const url = api2 + `agent/info`;
  return Request.get(url)
}

// 校验用户支付密码
export function checkAgentPayPassword (data) {
  const url = api2 + `validate/checkPayPassword`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 会员购买排行榜
export function dealerRank (page, per, source) {
  const url = api2 + `agent/rank?page=${page}&per=${per}&source=${source}`;
  return Request.get(url)
}

// 查看经销商资料
export function dealerInfo (uid) {
  const url = api2 + `agent/viewInfo?uid=${uid}`;
  return Request.get(url)
}

// 申请成为经销商
export function dealerApply (uid, type, u) {
  const url = api2 + `agent/apply?uid=${uid}&type=${type}&u=${u}`;
  return Request.get(url)
}

// 更新经销商联系方式
export function updateDealerInfo (data) {
  const url = api2 + `agent/updateInfo`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 更新是否在排行榜中展示
export function isInfoShow (show) {
  const url = api2 + `agent/isShow?show=${show}`;
  return Request.get(url)
}

// 经销商可升级列表展示
export function upgradeInfo (uid) {
  const url = api2 + `agent/upgradeList?uid=${uid}`;
  return Request.get(url)
}

// 经销商会员价格拿价单
export function priceForm () {
  const url = api2 + `agent/priceForm`;
  return Request.get(url)
}

// 经销商升级
export function dealerUpgrade (uid, from, type, u) {
  const url = api2 + `agent/upgrade?uid=${uid}&from=${from}&type=${type}&u=${u}`;
  return Request.get(url)
}

// 历史兑换搜索
export function exchangeList (date) {
  const url = api2 + `agent/orderList?date=${date}`;
  return Request.get(url)
}

// 商品套餐价格信息
export function packageList (goodsId) {
  const url = api2 + `agent/packageList?goodsId=${goodsId}`;
  return Request.get(url)
}

// 更新经销商联系方式
export function exchangeStepOne (data) {
  const url = api2 + `agent/exchange`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 兑换升级码支付提交
export function exchangeStepTwo (data) {
  const url = api2 + `agent/payOrder`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 我的升级码信息
export function codeInfo () {
  const url = api2 + `agent/codeInfo`;
  return Request.get(url)
}

// 升级码列表
/*export function codeList (per, page, peroid, sale, u) {
  const url = api2 + `agent/codeList?per=${per}&page=${page}&peroid=${peroid}&sale=${sale}&u=${u}`;
  return Request.get(url)
}*/
export function codeList (per, page, peroid, sale) {
  const url = api2 + `agent/codeList?per=${per}&page=${page}&peroid=${peroid}&sale=${sale}`;
  return Request.get(url)
}

// 更新升级码状态
export function updateCodeStatus (id, sale) {
  const url = api2 + `agent/updateCodeStatus?id=${id}&sale=${sale}`;
  return Request.get(url)
}

// 用户详情
export function userTokenInfo () {
  const url = api2 + `token/userInfo`;
  return Request.get(url)
}

// 第三方在售订单列表
export function tokenTradeList (per, page) {
  const url = api2 + `token/tradeList?per=${per}&page=${page}`;
  return Request.get(url)
}

// 官方渠道购买令牌第一步
export function officialTradeStepFirst () {
  const url = api2 + `token/platformTradeStepFirst`;
  return Request.get(url)
}

// 官方渠道购买令牌第2步
export function officialTradeStepSecond (data) {
  const url = api2 + `token/platformTradeStepSecond`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 官方渠道购买令牌第3步
export function officialTradeStepThird (data) {
  const url = api2 + `token/platformTradePay`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 我的出售订单列表
export function mySaleTradeList (per, page) {
  const url = api2 + `token/mySaleTradeList?per=${per}&page=${page}`;
  return Request.get(url)
}

// 出售订单撤销
export function saleOrderCancel (data) {
  const url = api2 + `token/saleOrderCancel`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 发布令牌出售订单
export function issueTokenOrder (data) {
  const url = api2 + `token/issueOrder`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 我的出售订单列表
export function issueOrderInfo (orderNo) {
  const url = api2 + `token/sellTradeInfo?orderNo=${orderNo}`;
  return Request.get(url)
}

// 查询自有闲置令牌数量
export function idleTokenNum () {
  const url = api2 + `token/selfNum`;
  return Request.get(url)
}

// 官方回购第1步
export function buyBackStepFirst () {
  const url = api2 + `token/buybackStepFirst`;
  return Request.get(url)
}

// 官方回购第2步
export function buyBackStepSecond (data) {
  const url = api2 + `token/buybackStepSecond`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 官方回购第3步
export function buyBackStepThird (data) {
  const url = api2 + `token/buybackStepThird`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 第三方渠道购买第一步
export function outsidePurchaseStepFirst () {
  const url = api2 + `token/outsideTradeStepFirst`;
  return Request.get(url)
}

// 第三方渠道购买第二步
export function outsidePurchaseStepSecond (data) {
  const url = api2 + `token/outsideTradeStepSecond`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 第三方渠道购买第三步
export function outsidePurchaseStepThird (data) {
  const url = api2 + `token/outsideTradePay`;
  return Request({
    url,
    method: 'post',
    data: Qs.stringify(data)
  })
}

// 令牌极验初始化
export function tokenGeetestInit () {
  const url = api2 + `validate/geetestInit`;
  return Request.get(url)
}

// 支付密码验证成功后获取短信验证码
export function tokenGetCode (data) {
  const url = api2 + `validate/getCode`;
  return Request({
    url,
    method: 'post',
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: Qs.stringify(data)
  })
}

// 我的回购排队列表
export function buyBackQueueList () {
  const url = api2 + `token/myBuyBackQueue`;
  return Request.get(url)
}

// 排队撤销
export function buyBackOrderCancel (data) {
  const url = api2 + `token/buyBackRankCancel`;
  return Request({
    url,
    method: 'post',
    headers : {
      "Content-Type":'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: Qs.stringify(data)
  })
}

// 我的令牌回购排队信息
export function buyBackRankInfo () {
  const url = api2 + `token/buyBackRankInfo`;
  return Request.get(url)
}

// 路由器令牌列表
export function routerTokenList (per, page) {
  const url = api2 + `token/tokenList?per=${per}&page=${page}`;
  return Request.get(url)
}

// 路由器令牌列表
export function routerTokenNodeList (tokenId) {
  const url = api2 + `token/tokenNodeList?tokenId=${tokenId}`;
  return Request.get(url)
}

// 令牌碎片质押撤销
export function chipDepositCancel (nodeId) {
  const url = api2 + `token/pledge?type=3&source=1&nodeId=${nodeId}`;
  return Request.get(url)
}

// 令牌质押撤销
export function tokenDepositCancel (tokenId) {
  const url = api2 + `token/pledge?type=3&source=1&tokenId=${tokenId}`;
  return Request.get(url)
}

// 刷新路由器质押数据
export function depositRouterInfo () {
  const url = api2 + `token/refreshNodeInfo?type=3`;
  return Request.get(url)
}

// 申请加入超级节点的矿工列表
export function minerApplyList (page, per) {
  const url = api2 + `super/user/minerApplyList?page=${page}&per=${per}`;
  return Request.get(url)
}

// 超级节点同意矿工加入
export function minerApplyPermit (minerUid) {
  const url = api2 + `super/user/minerApplyResponse?minerUid=${minerUid}&source=1`;
  return Request.get(url)
}

// 超级节点拒绝矿工加入
export function minerApplyDeny (minerUid) {
  const url = api2 + `super/user/minerApplyResponse?minerUid=${minerUid}&source=2`;
  return Request.get(url)
}

// 增加矿工可开设的节点数
export function addMinerNodeNum (minerUid, num) {
  const url = api2 + `super/user/addMinerNodeNum?minerUid=${minerUid}&num=${num}`;
  return Request.get(url)
}

// 修改审核模式
export function updateVerifyMode (status) {
  const url = api2 + `super/user/updateVerifyMode?status=${status}`;
  return Request.get(url)
}

// 获取旗下矿工每种类型节点的数量
export function minerNodeCount (minerId) {
  const url = api2 + `super/user/nodeCount?minerId=${minerId}`;
  return Request.get(url)
}

// 获取旗下矿工每种类型节点的详细信息
export function minerIncomeDetailList (minerId, source, page, per) {
  const url = api2 + `super/user/incomeDetail?minerId=${minerId}&source=${source}&page=${page}&per=${per}`;
  return Request.get(url)
}

// 超级节点置顶某个矿工
export function putMinerTop (minerId) {
  const url = api2 + `super/user/top?minerId=${minerId}&source=2`;
  return Request.get(url)
}

// 超级节点取消某个矿工置顶
export function cancelMinerTop (minerId) {
  const url = api2 + `super/user/top?minerId=${minerId}&source=1`;
  return Request.get(url)
}

// 检查当前矿工是否满足删除条件
export function deleteCondition (minerUid) {
  const url = api2 + `super/user/checkCanDelete?minerUid=${minerUid}`;
  return Request.get(url)
}

// 移除矿工(强制删除和普通删除都调这个接口)
export function removeMiner (minerId, code) {
  const url = api2 + `super/user/removeMiner?minerId=${minerId}&code=${code}`;
  return Request.get(url)
}

// 新挖矿看板信息
export function newMiningInfo () {
  const url = api2 + `mining/info`;
  return Request.get(url)
}
// 节点列表
export function newNodeList (page, per) {
  const url = api2 + `mining/node/list?page=${page}&per=${per}`;
  return Request.get(url)
}
// 单个节点质押&解除质押
export function singleNodePledge (nodeId, way) {
  const url = api2 + `mining/node/pledge?node_id=${nodeId}&way=${way}`;
  return Request.get(url)
}
// 批量节点质押&解除质押
/*export function batchNodePledge (nodeId, way) {
  const url = api2 + `mining/node/pledge/batch?node_id=${nodeId}&way=${way}`;
  return Request.get(url)
}*/
export function batchNodePledge (data) {
  const url = api2 + `mining/node/pledge/batch`;
  return Request({
    url,
    method: 'post',
    headers : {
      "Content-Type":'application/json; charset=UTF-8'
    },
    data
    // data: Qs.stringify(data)
  })
}
// 收益明细(列表)
export function newProfitList (page, per) {
  const url = api2 + `mining/profit/list?page=${page}&per=${per}`;
  return Request.get(url)
}
// 收益明细(详情)
export function newProfitDetail (listId) {
  const url = api2 + `mining/profit/detail?list_id=${listId}`;
  return Request.get(url)
}
// 判断当前用户身份信息
export function newDepositUserInfo () {
  const url = api2 + `mining/role`;
  return Request.get(url)
}
// 新挖矿里面成为矿工
export function newSuperNodeMiner (code) {
  const url = api2 + `mining/join?super_uid=${code}`;
  return Request.get(url)
}
// 删除节点
export function deleteNode (node_id) {
  const url = api2 + `mining/node/delete?node_id=${node_id}`;
  return Request.get(url)
}
// 校验是否首次使用yta
export function ytaCheck (uid) {
  const url = api2 + `yta/check?uid=${uid}`;
  return Request.get(url)
}
// 绑定YTA地址
export function ytaAddressBind (address) {
  const url = api2 + `yta/bind?address=${address}`;
  return Request.get(url)
}
// 换绑YTA地址
export function ytaAddressUpdate (address, u) {
  const url = api2 + `yta/bind/update?address=${address}&u=${u}`;
  return Request.get(url)
}
// 今日币价
export function todayPrice () {
  const url = api2 + `yta/coin/price`;
  return Request.get(url)
}
// yta兑换记录
export function ytaExchangeList (page, per) {
  const url = api2 + `yta/recharge/log?page=${page}&per=${per}`;
  return Request.get(url)
}
// cvnt 兑换 yta
export function ytaExchange (cvn, u) {
  const url = api2 + `yta/recharge?cvn=${cvn}&u=${u}`;
  return Request.get(url)
}









































